package com.duobao.server;
import java.awt.FlowLayout;
import java.awt.Font;
import java.util.*;

import javax.swing.JLabel;
import javax.swing.JPanel;

import com.duobao.uitl.Zuanhuan;
import com.duobao.view.ZhangdouJPanel;

public class NPC implements Runnable
{
    protected int id;
    protected int leib;//1 npc,2 hero
    protected String name;//NPC名字
    protected boolean ydong;//是否可以移动
    protected boolean hunmi;//是否昏迷
    protected boolean siwang;//是否死亡
    protected boolean autozdou;//是否可以自动战斗
    protected boolean sex;//NPC性别： true为男，false为女
    protected int age;//NPC年龄
    protected int  chushiMap;//出生地
    protected int  location;//所在地图位置
    protected String ageDa;//NPC年龄大写
    protected int MaxHP;//NPC最高气血
    protected int HP;//NPC当前气血
    protected int MaxSP;//NPC最高精神
    protected int SP;//NPC当前精神
    protected int MaxMP;//NPC最高内力
    protected int MP;//NPC当前内力
    protected int MaxProficiency;//NPC最高潜能
    protected int proficiency;//NPC当前潜能
    protected int cultivationN;//NPC修行年
    protected int cultivationY;//NPC修行天
    protected int cultivationR;//NPC修行时
    protected int SHai;//NPC兵器伤害力
    protected int FYu;//NPC盔甲保护力
    protected int SDuo;//NPC躲闪力
    protected String XiuWei;//NPC修行
    protected Vector<Equip> equip;//NPC装备
    protected int  jiaopai;//NPC教派，0普通百姓,1少林，2五岳，3魔教
    public  int Daishu;//NPC代数
    protected String JiaoC;//NPC教称
    protected String ChengWei;//NPC称谓
    protected NPC shifu;
    protected String Qxue;//NPC气血描述
    protected Vector<WuGong> WGs;//NPC武功
    protected String WGMS;//NPC武功描述
    protected String CSMS;//NPC出手描述
    protected int MaxJBWg;//最大基本武功
    protected Vector<Equip> equip2;//NPC随身物品
    protected int FZ;//装备负重
    protected String YHai[];//要害
    protected int[] ZH= new int[9];//综合,1刀，2剑，3拳，4杖,5斧,6戟,7内功,8轻功,9招架,
    protected ZhangDou ZD;//战斗
    protected long swTime;//死亡时间
    protected Equip ee;//昏迷物品
    public NPC(int id,boolean yidong,boolean autozdou,String name,boolean sex,int age,int location,int JiaoPai,int Daishu,Equip equip[],WuGong WGs[])
    {
        this.id=id;
        this.ydong=yidong;
        this.leib=1;
        this.siwang=false;
        this.hunmi=false;
        this.autozdou=autozdou;
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.location = location;
        this.chushiMap=location;
        this.jiaopai = JiaoPai;
        this.Daishu = Daishu;
        this.equip2 = new Vector<Equip>();
        this.equip = new Vector<Equip>();
        this.shifu=null;
        for(int i=0;i<equip.length;i++)
        {
            this.equip2.add(equip[i]);
            if(equip[i].isZB())
            {
                this.equip.add(equip[i]);
            }
        }
        this.WGs = new Vector<WuGong>();
        for(int i=0;i<WGs.length;i++)
        {
            this.WGs.add(WGs[i]);
        }

        this.setxiuwei();

        this.MaxHP = this.age*20+(this.cultivationN/40)*20;
        this.HP = this.MaxHP;
        this.MaxSP = this.age*20+(this.cultivationN/160)*20;
        //this.SP = this.MaxSP;
        this.SP =1000000;
        this.MaxMP = this.getWg("基本内功").getLv()*10;
        this.MP = this.MaxMP;
        this.MaxProficiency =300 + this.cultivationN*5;
        this.proficiency = 60000;
        this.YHai = new String[]{"面门","胸口","后背","左肩","右肩","屁股","右腿","左腿"};
        this.setXiuWei();
        this.SHai = this.Shai();
        this.FYu = this.Fyu();
        this.SDuo = this.Sduo();
        this.setQxue();
        this.setJiaoC();
        this.setChengWei();
        this.setAgeDa();
        this.setPZJBWg();
        this.setMaxJBWg();
        this.setWGMS();
        this.setCSMS();
        this.setFZ();
        this.setZH();
    }

    public int getChushiMap() {
        return chushiMap;
    }

    public void setChushiMap(int chushiMap) {
        this.chushiMap = chushiMap;
    }

    public ZhangDou getZD() {
        return ZD;
    }

    public boolean isHunmi() {
        return hunmi;
    }

    public void setHunmi(boolean hunmi) {
        this.hunmi = hunmi;
    }

    public boolean isSiwang() {
        return siwang;
    }

    public void setSiwang(boolean siwang) {
        this.siwang = siwang;
    }

    public void setZD(ZhangDou zD) {
        ZD = zD;
    }
    public void genxinLoca()
    {
        for(int i=0;i<this.equip2.size();i++)
        {
            this.equip2.get(i).setLocation(this.location);
        }
    }
    private void setxiuwei()
    {
        int maxwg=this.getMaxWg();

        Float xiuwei=maxwg*maxwg*maxwg/1000.0f;
        int nian=xiuwei.intValue();
        Float tianf=((xiuwei-nian)*250);
        int tian=tianf.intValue();
        Float shic=(tianf-tian)*12;
        int sc=shic.intValue();

        this.cultivationN = nian;
        this.cultivationY = tian;
        this.cultivationR = sc;
    }

    public long getSwTime() {
        return swTime;
    }

    public void setSwTime(long swTime) {
        this.swTime = swTime;
    }

    public WuGong duobiWugong()
    {
        WuGong wg=null;
        WuGong w=this.getWg("基本轻功");
        if(w.getPZWg()==null)
        {
            wg = w;
        }else
        {
            wg = w.getPZWg();
        }
        return wg;
    }
    public WuGong zaojiaWugong()
    {
        WuGong wg=null;
        WuGong w=this.getWg("基本招架");
        if(w.getPZWg()==null)
        {
            wg = chushouWugongleib();
        }else
        {
            wg = w.getPZWg();
        }
        return wg;
    }
    public WuGong chushouWugongleib()
    {
        WuGong wg=null;
        if(this.getZbW()==null)
        {
            wg=this.getWg("基本拳脚");
        }else
        {
            wg = this.getJBWG(this.getZbW().getCategory());
        }

        return wg;
    }
    public WuGong chushouWugong()
    {
        WuGong wg=null;
        if(this.getZbW()==null)
        {
            WuGong w=this.getWg("基本拳脚");
            if(w.getPZWg()==null)
            {
                wg = w;

            }else
            {
                wg = w.getPZWg();
            }

        }else
        {
            if(this.getJBWG(this.getZbW().getCategory()).getPZWg()==null)
            {
                wg = this.getJBWG(this.getZbW().getCategory());
            }else
            {
                wg = this.getJBWG(this.getZbW().getCategory()).getPZWg();
            }

        }

        return wg;
    }
    //学艺书
    public void  xueyiShu(WuGong wg)
    {

        int a=((int)(((this.SP-(int) (this.MaxSP*0.1)))));

        if(wg.getBengjijingyan()+a<wg.getshenjijy())
        {
            wg.setBengjijingyan(wg.getBengjijingyan()+a);//增加本级经验
            this.SP=(int)(this.MaxSP*0.1);//更新精神
            wg.setEndurance();//重新设置熟练度
        }else
        {
            int cha=wg.getshenjijy()-wg.getBengjijingyan();

            this.SP=this.SP-cha;
            wg.setBengjijingyan(0);
            wg.setLv(wg.getLv()+1);
            wg.setEndurance();

        }


    }
    public boolean xueyi_shuIf(WuGong wg)
    {
        boolean b=false;
        int a=((int)(((this.SP-(int) (this.MaxSP*0.1)))));

        if(wg.getBengjijingyan()+a<wg.getshenjijy())
        {

        }else
        {
            b=true;
        }

        return b;
    }
    //学艺拜师
    public void  xueyi_Baishi(WuGong wg)
    {

        int a=((int)(((this.SP-(int) (this.MaxSP*0.1)))));

        if(wg.getBengjijingyan()+a<wg.getshenjijy())
        {
            if(this.proficiency>=a)
            {
                wg.setBengjijingyan(wg.getBengjijingyan()+a);//增加本级经验
                this.proficiency=this.proficiency-a;
                this.SP=(int)(this.MaxSP*0.1);//更新精神
                wg.setEndurance();//重新设置熟练度
            }else
            {
                wg.setBengjijingyan(wg.getBengjijingyan()+this.proficiency);//增加本级经验
                this.proficiency=0;
                this.SP=this.MaxSP-this.proficiency;//更新精神
                wg.setEndurance();//重新设置熟练度
            }

        }else
        {
            int cha=wg.getshenjijy()-wg.getBengjijingyan();

            if(this.proficiency>=cha)
            {
                this.SP=this.SP-cha;
                this.proficiency=this.proficiency-cha;
                wg.setBengjijingyan(0);
                wg.setLv(wg.getLv()+1);
                wg.setEndurance();

            }else
            {
                this.SP=this.SP-this.proficiency;
                wg.setBengjijingyan(wg.getBengjijingyan()+this.proficiency);
                this.proficiency=0;
                wg.setEndurance();
            }


        }


    }
    public boolean xueyi_baishiIf(WuGong wg)
    {
        boolean b=false;
        int a=((int)(((this.SP-(int) (this.MaxSP*0.1)))));

        if(wg.getBengjijingyan()+a<wg.getshenjijy())
        {
        }else
        {
            int cha=wg.getshenjijy()-wg.getBengjijingyan();

            if(this.proficiency>=cha)
            {
                b=true;
            }else
            {

            }


        }

        return b;
    }
    public boolean getBaishi()//判断是否是倒数第二代弟子，用于学艺判断
    {
        boolean b=false;
        if((this.jiaopai==1 && this.Daishu==5) || (this.jiaopai==2 && this.Daishu==3) || (this.jiaopai==3 && this.Daishu==4))
        {
            b=true;
        }
        return b;
    }
    public NPC getShifu() {
        return shifu;
    }

    public void setShifu(NPC shifu) {
        this.shifu = shifu;
    }

    public String getsexMiShu()//获得性别称谓
    {
        String s="她";
        if(this.sex)
        {
            s="他";
        }
        return s;

    }
    //NPC移动
    public void YiDong(int FX)
    {
        if(this.hunmi || this.siwang)
        {

        }else
        {
            Map map1=Maps.getMap(this.getLocation());
            map1.getNpcs().remove(this);


            Map map2=Maps.getMap((Maps.getMap(this.getLocation()).getDirection())[FX]);
            map2.getNpcs().add(this);


            this.setLocation((Maps.getMap(this.getLocation()).getDirection())[FX]);
            this.genxinLoca();
        }

    }
    //获取所有基本武功总数
    public int getJBWGS()
    {
        int i = 0;
        for(int j=0;j<this.WGs.size();j++)
        {
            WuGong  wg = this.WGs.get(j);
            if(wg.getCategory()==2)
            {
                ++i;
            }
        }
        return i;
    }

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    //获取特定类的基本武功
    public WuGong getJBWG(int a)
    {
        WuGong  wg=null;
        for(int j=0;j<this.WGs.size();j++)
        {
            WuGong wg1 = this.WGs.get(j);
            if(wg1.getCategory()==2 && wg1.getCategory2()==a)
            {
                wg = wg1;
                break;
            }
        }
        return wg;
    }
    //获取特定类的所有特殊武功总数
    public int getJBWGJFS(int a)
    {
        int i = 0;
        for(int j=0;j<this.WGs.size();j++)
        {
            WuGong  wg = this.WGs.get(j);
            if(wg.getCategory()==1 && wg.getCategory2()==a)
            {
                ++i;
            }
        }
        return i;
    }
    //获取所有特定类的特殊武功集合
    public Vector<WuGong> getJBWGSZ(int a)
    {
        Vector<WuGong> wu = new Vector<WuGong>();
        for(int j=0;j<this.WGs.size();j++)
        {
            WuGong  wg = this.WGs.get(j);
            if(a==9)
            {
                if(wg.getCategory()==1 && wg.getCategory2()!=8 && wg.getCategory2()!=7)
                {
                    wu.add(wg);
                }
            }else
            {
                if(wg.getCategory()==1 && wg.getCategory2()==a)
                {
                    wu.add(wg);
                }
            }
        }
        return wu;
    }
    //判断是否装备武器
    public boolean isZbW()
    {
        boolean Zb = false;
        for(int i=0;i<this.equip.size();i++)
        {
            Equip e = this.equip.get(i);
            if(e.getCategory()<=6)
            {
                Zb = true;
                break;
            }
        }
        return Zb;
    }
    //判断是否装备衣服
    public boolean isZbY()
    {
        boolean Zb = false;
        for(int i=0;i<this.equip.size();i++)
        {
            Equip e = this.equip.get(i);
            if(e.getCategory()==8)
            {
                Zb = true;
                break;
            }
        }

        return Zb;
    }
    //判断是否装备甲
    public boolean isZbJ()
    {
        boolean Zb = false;
        for(int i=0;i<this.equip.size();i++)
        {
            Equip e = this.equip.get(i);
            if(e.getCategory()==7)
            {
                Zb = true;
                break;
            }
        }

        return Zb;
    }
    //判断是否装备鞋
    public boolean isZbX()
    {
        boolean Zb = false;
        for(int i=0;i<this.equip.size();i++)
        {
            Equip e = this.equip.get(i);
            if(e.getCategory()==9)
            {
                Zb = true;
                break;
            }
        }

        return Zb;
    }
    //获取装备的武器
    public Equip getZbW()
    {
        Equip equi = null;
        for(int i=0;i<this.equip.size();i++)
        {
            Equip e = this.equip.get(i);
            if(e.getCategory()<=6)
            {
                equi = e ;
                break;
            }
        }

        return equi;
    }
    //获取装备的衣服
    public Equip getZbY()
    {
        Equip equi = null;
        for(int i=0;i<this.equip.size();i++)
        {
            Equip e = this.equip.get(i);
            if(e.getCategory()==8)
            {
                equi = e ;
                break;
            }
        }

        return equi;
    }
    //获取装备的甲
    public Equip getZbJ()
    {
        Equip equi = null;
        for(int i=0;i<this.equip.size();i++)
        {
            Equip e = this.equip.get(i);
            if(e.getCategory()==7)
            {
                equi = e ;
                break;
            }
        }

        return equi;
    }
    //获取装备的鞋
    public Equip getZbX()
    {
        Equip equi = null;
        for(int i=0;i<this.equip.size();i++)
        {
            Equip e = this.equip.get(i);
            if(e.getCategory()==9)
            {
                equi = e ;
                break;
            }
        }

        return equi;
    }
    //获取特定的随身装备
    public Equip getEquip(String name,int id)
    {
        Equip equi = null;
        for(int i=id;i>=0;i--)
        {
            Equip eq=null;
            try {
                eq = this.equip2.get(id);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                continue;
            }
            if(eq.getMsName().equals(name))
            {
                equi = eq;
                break;
            }
        }
        return equi;
    }
    //获取随身装备的黄金
    public Equip isHJ()
    {
        Equip Zb = null;
        for(int i=0;i<this.equip2.size();i++)
        {
            Equip e = this.equip2.get(i);
            if(e.getCategory()==10)
            {
                Zb = e;
                break;
            }
        }

        return Zb;
    }
    //获取随身装备的白银
    public Equip isBY()
    {
        Equip Zb = null;
        for(int i=0;i<this.equip2.size();i++)
        {
            Equip e = this.equip2.get(i);
            if(e.getCategory()==11)
            {
                Zb = e;
                break;
            }
        }

        return Zb;
    }
    //获取随身装备的铜板
    public Equip isTB()
    {
        Equip Zb = null;
        for(int i=0;i<this.equip2.size();i++)
        {
            Equip e = this.equip2.get(i);
            if(e.getCategory()==12)
            {
                Zb = e;
                break;
            }
        }

        return Zb;
    }
    public int getFZ() {
        return FZ;
    }
    public void setHuobi(Equip huobi)//设置捡起货币
    {
        Equip Zb = null;
        boolean b=false;
        for(int i=0;i<this.equip2.size();i++)
        {
            Equip e = this.equip2.get(i);
            if(e.getCategory()==huobi.getCategory())
            {
                Zb = e;
                b=true;
                break;
            }
        }
        if(b)
        {
            if(Zb.getCategory()==10)
            {
                Zb.setJZH(Zb.getJZH()+huobi.getJZH());
                Zb.setFZ(Zb.getJZH()/10);
            }
            else if(Zb.getCategory()==11)
            {
                Zb.setJZB(Zb.getJZB()+huobi.getJZB());
                Zb.setFZ(Zb.getJZB()/10);
            }else if(Zb.getCategory()==12)
            {
                Zb.setJZT(Zb.getJZT()+huobi.getJZT());
                Zb.setFZ(Zb.getJZT()/10);
            }
        }else
        {
            this.equip2.add(huobi);
        }
    }
    //获取NPC负重
    public void setFZ() {
        this.FZ = 0;
        for(int i=0;i<this.equip2.size();i++)
        {
            this.FZ = this.FZ+ this.equip2.get(i).getFZ();
        }
    }
    public String getWGMS() {
        return WGMS;
    }
    public String getCSMS() {
        return CSMS;
    }
    //获取出手描述
    public void setCSMS() {
        int cs = this.MaxJBWg+this.SHai;
        if(cs<10)
        {
            this.CSMS = "极轻";
        }else if(cs<40)
        {
            this.CSMS = "很轻";
        }else if(cs<90)
        {
            this.CSMS = "不重";
        }else if(cs<160)
        {
            this.CSMS = "不轻";
        }else if(cs<300)
        {
            this.CSMS = "很重";
        }else if(cs<600)
        {
            this.CSMS = "极重";
        }else
        {
            this.CSMS = "匪夷所思";
        }
    }
    //获取武功描述
    public void setWGMS() {
        int wgms = this.MaxJBWg;
        if(wgms<50)
        {
             if(wgms<5)
             {
                this.WGMS = "不堪一击";
             }else if(wgms<10)
             {
                this.WGMS = "毫不足虑";
             }else if(wgms<20)
             {
                this.WGMS = "不足挂齿";
             }else if(wgms<30)
             {
                this.WGMS = "普普通通";
             }else if(wgms<40)
             {
                   this.WGMS = "马马虎虎";
             }else if(wgms<50)
             {
                 this.WGMS = "初窥门径";
             }
        }else if(wgms<160)
        {
             if(wgms<60)
             {
                 this.WGMS = "平淡无奇";
             }else if(wgms<70)
             {
                 this.WGMS = "半生不熟";
             }else if(wgms<80)
             {
                 this.WGMS = "略有小成";
             }else if(wgms<100)
             {
                 this.WGMS = "已有小成";
             }else if(wgms<130)
             {
                 this.WGMS = "驾轻就熟";
             }else if(wgms<160)
             {
                 this.WGMS = "了然于胸";
             }
        }else if(wgms<340)
        {
             if(wgms<190)
             {
                  this.WGMS = "炉火纯青";
             }else if(wgms<220)
             {
                  this.WGMS = "略有大成";
             }else if(wgms<250)
             {
                  this.WGMS = "神乎其技";
             }else if(wgms<280)
             {
                  this.WGMS = "已有大成";
             }else if(wgms<310)
             {
                  this.WGMS = "一代宗师";
             }else if(wgms<340)
             {
                  this.WGMS = "震古烁今";
             }
        }else if(wgms<520)
        {
             if(wgms<370)
             {
                 this.WGMS = "惊世骇俗";
             }else if(wgms<400)
             {
                 this.WGMS = "傲视群雄";
             }else if(wgms<430)
             {
                this.WGMS = "出神入化";
             }else if(wgms<460)
             {
                this.WGMS = "笑傲江湖";
             }else if(wgms<490)
             {
                this.WGMS = "举世无双";
             }else if(wgms<520)
             {
                this.WGMS = "空前绝后";
             }
        }else
        {
             if(wgms<550)
             {
                this.WGMS = "飞花摘叶";
             }else if(wgms<580)
             {
                this.WGMS = "神功内蕴";
             }else if(wgms<610)
             {
                this.WGMS = "深藏不露";
             }else if(wgms<640)
             {
                this.WGMS = "深不可测";
              }else if(wgms<670)
             {
                this.WGMS = "返璞归真";
             }else
             {
               this.WGMS = "天人合一";
             }
        }
    }
    //获取最高等级武功
    public int getMaxWg()
    {
        int max = this.WGs.get(1).getLv();
        for(int i=0;i<this.WGs.size();i++)
        {
            WuGong wg = this.WGs.get(i);
            if(wg.getLv()>max)
            {
                max = wg.getLv();
            }
        }
        return max;
    }
    public int  getMaxJBWg()
    {
        return this.MaxJBWg;
    }
    //设置最高基本武功综合
    public void setMaxJBWg()
    {
        int max = 0;
        for(int i=0;i<this.WGs.size();i++)
        {
            WuGong wg;
            if(this.WGs.get(i).getCategory()==2)
            {
                wg = this.WGs.get(i);
                if(wg.getPZWg() == null)
                {
                    if(wg.getLv()>max)
                    {
                        max = wg.getLv()/2;
                    }
                }else
                {
                    if((wg.getLv()/2+wg.getPZWg().getLv())>max)
                    {
                        max = wg.getLv()/2+wg.getPZWg().getLv();
                    }
                }
            }
        }
        this.MaxJBWg =  max;
    }
    //配置武功
    public void setPZJBWg()
    {
        for(int i=0;i<this.WGs.size();i++)
        {
            WuGong wg,wg2;
            if(this.WGs.get(i).getCategory()==2)
            {
                wg = this.WGs.get(i);
                for(int j=0;j<this.WGs.size();j++)
                {
                    wg2 = this.WGs.get(j);
                    if(wg2.getCategory()==1 && (wg.getCategory2()==wg2.getCategory2() || (wg.getCategory2()==9 && wg2.getCategory2()!=7 && wg2.getCategory2()!=8)))
                    {
                        wg.setPZWg(wg2);
                        wg2.setPZ(true);
                    }
                }
            }
        }
    }
    public String[] getYHai() {
        return YHai;
    }
    public void setYHai(String[] yHai) {
        YHai = yHai;
    }
    //获取武功
    public WuGong getWg(String S)
    {
        WuGong  Wg=null;
        for(int i=0;i<this.WGs.size();i++)
        {
            WuGong wg = this.WGs.get(i);
            if(wg.getName().equals(S))
            {
                Wg = wg;
                break;
            }
        }
        return Wg;
    }
    //获取伤害
    public int  Shai()
    {
        int Shai=0;

        for(int i=0;i<this.equip.size();i++)
        {
            if(equip.get(i).isZB())
            {
                Shai=equip.get(i).getATK()+Shai;
            }
        }
        return Shai;
    }
    //获取防御
    public int  Fyu()
    {
        int Fyu=0;

        for(int i=0;i<this.equip.size();i++)
        {
            if(equip.get(i).isZB())
            {
                Fyu=equip.get(i).getDEF()+Fyu;
            }
        }
        return Fyu;
    }
    //获取闪躲
    public int  Sduo()
    {
        int Sduo=0;

        for(int i=0;i<this.equip.size();i++)
        {
            if(equip.get(i).isZB())
            {
               Sduo=equip.get(i).getDodge()+Sduo;
            }
        }
        return Sduo;
    }
    public Vector<Equip> getEquip2() {
        return equip2;
    }
    public void setEquip2(Vector<Equip> equip2) {
        this.equip2 = equip2;
    }
    public Vector<WuGong> getWGs() {
        return WGs;
    }
    public void setWGs(Vector<WuGong> wGs) {
        WGs = wGs;
    }
    public String getAgeDa() {
        return ageDa;
    }
    public void setAgeDa() {//设置年龄
        this.ageDa = Zuanhuan.zhuang(this.age);
    }
    public int getCultivationN() {
        return cultivationN;
    }
    public void setCultivationN(int cultivationN) {
        this.cultivationN = cultivationN;
    }
    public int getCultivationY() {
        return cultivationY;
    }
    public void setCultivationY(int cultivationY) {
        this.cultivationY = cultivationY;
    }
    public int getCultivationR() {
        return cultivationR;
    }
    public void setCultivationR(int cultivationR) {
        this.cultivationR = cultivationR;
    }
    public String getXiuWei() {
        return XiuWei;
    }
    public void addcultivation(int n,int y,int r)
    {
        this.cultivationN=this.cultivationN+n;
        this.cultivationY=this.cultivationY+y;
        this.cultivationR=this.cultivationR+r;

    }

    public void jzhi()//进值
    {
        if(this.cultivationR>=12)
        {
            this.cultivationY = this.cultivationY+this.cultivationR/12;
            this.cultivationR = this.cultivationR%12;
        }if(this.cultivationY>=250)
        {
            this.cultivationN = this.cultivationN+this.cultivationY/250;
            this.cultivationY = this.cultivationY%250;
        }
    }
    public void tzhi()//退值
    {
        if(this.cultivationR<0)
        {
            this.cultivationY = this.cultivationY-1;
            this.cultivationR = this.cultivationR+12;
        }if(this.cultivationY<0)
        {
            this.cultivationN = this.cultivationN-1;
            this.cultivationY = this.cultivationY+250;
        }
    }
    //设置修为
    public void setXiuWei() {
        this.jzhi();
        this.tzhi();
        this.XiuWei="";
        if(this.cultivationN!=0)
        {
            this.XiuWei = Zuanhuan.zhuang(this.cultivationN)+"年";
        }

        if(this.cultivationY!=0)
        {
            this.XiuWei = this.XiuWei+Zuanhuan.zhuang(this.cultivationY)+"天";
        }

        if(this.cultivationR!=0)
        {
            this.XiuWei = this.XiuWei+Zuanhuan.zhuang(this.cultivationR)+"时辰";
        }
    }
    public int getJiaoPai() {
        return this.jiaopai;
    }
    public void setJiaoPai(int jiaoPai) {
        this.jiaopai = jiaoPai;
    }
    public String getQxue() {
        return Qxue;
    }
    //设置气血描述
    public void setQxue() {
        double d = ((double)this.HP/(double)this.MaxHP);
        if(d>0.9)
        {
            this.Qxue = "气血充盈";
        }else if(d>0.8)
        {
            this.Qxue = "有点疲倦了";
        }else if(d>0.7)
        {
            this.Qxue = "手脚不太灵光";
        }else if(d>0.6)
        {
            this.Qxue = "受了点轻伤";
        }else if(d>0.5)
        {
            this.Qxue = "受伤着实不轻";
        }else if(d>0.4)
        {
            this.Qxue = "伤痕累累";
        }else if(d>0.3)
        {
            this.Qxue = "深受重伤";
        }else
        {
            this.Qxue = "命在旦夕";
        }
    }
    //获取代数
    public String getDaishu() {
        String  daishu="无";
        if(this.Daishu==1)
        {
            daishu="一";
        }else if(this.Daishu==2)
        {
            daishu="二";
        }else if(this.Daishu==3)
        {
            daishu="三";
        }else if(this.Daishu==4)
        {
            daishu="四";
        }else if(this.Daishu==5)
        {
            daishu="五";
        }else if(this.Daishu==6)
        {
            daishu="六";
        }
        return daishu;
    }
    public void setDaishu(int daishu) {
        Daishu = daishu;
    }
    public String getJiaoC() {
        return JiaoC;
    }
    //教派名称
    public String getJiaopaiName()
    {
        String str="";
        switch(this.jiaopai)
        {
            case 0:str="普通百姓";break;
            case 1:str="少林";break;
            case 2:str="五岳";break;
            case 3:str="魔教";break;
        }
        return str;

    }
    //设置教称
    public void setJiaoC() {
        switch(this.jiaopai)
        {
            case 0:this.JiaoC="普通百姓";break;
            default :this.JiaoC=this.getJiaopaiName()+"第"+this.getDaishu()+"代弟子";break;
        }
    }
    public String getChengWei() {
        return ChengWei;
    }
    //设置称谓
    public void setChengWei() {
        if(this.jiaopai==3)
        {
            if(this.cultivationN >=5000)
            {
                this.ChengWei = "长老";
            }else if(this.cultivationN >=2000)
            {
                this.ChengWei = "堂主";
            }else if(this.cultivationN >=512)
            {
                this.ChengWei = "护法";
            }else if(this.cultivationN >=216)
            {
                this.ChengWei = "护教";
            }else if(this.cultivationN >=64)
            {
                this.ChengWei = "掌旗手";
            }else
            {
                this.ChengWei = "教众";
            }
        }else if(this.jiaopai==1)
        {
            if(this.cultivationN >=5000)
            {
                this.ChengWei = "圣僧";
            }else if(this.cultivationN >=2000)
            {
                this.ChengWei = "长老";
            }else if(this.cultivationN >=512)
            {
                this.ChengWei = "尊者";
            }else if(this.cultivationN >=216)
            {
                this.ChengWei = "禅师";
            }else if(this.cultivationN >=64)
            {
                this.ChengWei = "比丘";
            }else
            {
                this.ChengWei = "僧众";
            }
        }else if(this.jiaopai==2)
        {
            if(this.cultivationN >=5000)
            {
                this.ChengWei = "剑神";
            }else if(this.cultivationN >=2000)
            {
                this.ChengWei = "剑圣";
            }else if(this.cultivationN >=512)
            {
                this.ChengWei = "剑尊";
            }else if(this.cultivationN >=216)
            {
                this.ChengWei = "剑豪";
            }else if(this.cultivationN >=64)
            {
                this.ChengWei = "剑侠";
            }else
            {
                this.ChengWei = "剑士";
            }
        }else
        {
            this.ChengWei = "平民";
        }
    }
    public void setZH() {//设置综合
        for(int i=0;i<this.WGs.size();i++)
        {
            WuGong e = this.WGs.get(i);
            if(e.getCategory()==2)
            {
                if(e.getPZWg()==null)
                {
                    this.ZH[e.getCategory2()-1]=e.getLv()/2;
                }else
                {
                    this.ZH[e.getCategory2()-1]=((e.getLv()/2)+e.getPZWg().getLv());
                }
            }
        }
    }
    public int[] getZH() {
        return ZH;
    }
    public Vector<Equip> getEquip() {
        return equip;
    }
    public void setEquip(Vector<Equip> equip) {
        this.equip = equip;
    }
    public int getSHai() {
        return SHai;
    }
    public void setSHai(int sHai) {
        SHai = sHai;
    }
    public int getFYu() {
        return FYu;
    }
    public void setFYu(int fYu) {
        FYu = fYu;
    }
    public int getSDuo() {
        return SDuo;
    }
    public void setSDuo(int sDuo) {
        SDuo = sDuo;
    }
    public int getMaxProficiency() {
        return MaxProficiency;
    }
    public void setMaxProficiency(int maxProficiency) {
        MaxProficiency = maxProficiency;
    }
    public int getProficiency() {
        return proficiency;
    }
    public void setProficiency(int proficiency) {
        this.proficiency = proficiency;
    }
    public void addProficiency(int pro) {
        if(this.proficiency+pro<this.MaxProficiency)
        {
            this.proficiency = this.proficiency+pro;
        }else
        {
            this.proficiency=this.MaxProficiency;
        }

    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public boolean isSex() {
        return sex;
    }
    public void setSex(boolean sex) {
        this.sex = sex;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public int getMaxHP() {
        return MaxHP;
    }
    public void setMaxHP(int maxHP) {
        MaxHP = maxHP;
    }
    public int getHP() {
        return HP;
    }
    public void setHP(int hP) {
        HP = hP;
    }
    public int getMaxSP() {
        return MaxSP;
    }
    public void setMaxSP(int maxSP) {
        MaxSP = maxSP;
    }
    public int getSP() {
        return SP;
    }
    public void setSP(int sP) {
        SP = sP;
    }
    public int getMaxMP() {
        return MaxMP;
    }
    public void setMaxMP(int maxMP) {
        MaxMP = maxMP;
    }
    public int getMP() {
        return MP;
    }
    public void setMP(int mP) {
        MP = mP;
    }
    public int getLocation() {
        return location;
    }
    public void setLocation(int location) {
        this.location = location;
    }

    public ZhangDou setjinruzdou(NPC npc)
    {
        ZhangDou zdou=null;
        if(npc.getZD()!=null && this.getZD()!=null)
        {
            System.out.println("正在战斗中");
        }else if(npc.getZD()!=null && this.getZD()==null)
        {
            //小心战斗线程没有结束!
            if(npc.getZD().getNpc()==npc)
            {
                npc.getZD().getNpcs().add(this);
                zdou=npc.getZD();
            }else
            {

                if(npc.getZD().getNpcs().size()==1)
                {
                    npc.getZD().diaohuan();
                    npc.getZD().getNpcs().add(this);
                    this.setZD(npc.getZD());
                    zdou=npc.getZD();
                }else
                {
                    npc.getZD().getNpcs().remove(npc);

                    Vector<NPC> npcs= new Vector<NPC>();
                    npcs.add(this);
                    ZhangDou zd=new ZhangDou(this,npcs,location);
                    npc.setZD(zd);
                    npc.setZD(zd);
                    zdou=zd;
                }
//
            }

        }else if(npc.getZD()==null && this.getZD()!=null)
        {
            if(this.getZD().getNpc()==this)
            {
                this.getZD().getNpcs().add(npc);
                npc.setZD(this.getZD());
                zdou=npc.getZD();
            }else
            {
                if(this.getZD().getNpcs().size()==1)
                {
                    this.getZD().diaohuan();
                    this.getZD().getNpcs().add(npc);
                    npc.setZD(this.getZD());
                    zdou=npc.getZD();
                }else
                {
                    this.getZD().getNpcs().remove(this);


                    Vector<NPC> npcs= new Vector<NPC>();
                    npcs.add(npc);
                    ZhangDou zd=new ZhangDou(this,npcs,location);
                    npc.setZD(zd);
                    this.setZD(zd);
                    zdou=zd;
                }
            }

        }else if(npc.getZD()==null && this.getZD()==null)
        {
            Vector<NPC> npcs= new Vector<NPC>();
            npcs.add(npc);
            ZhangDou zd=new ZhangDou(this,npcs,location);
            npc.setZD(zd);
            this.setZD(zd);
            zdou=zd;
        }
        return zdou;
    }
    public void AutoXZ()//自动行走
    {
        if(this.ydong && this.ZD==null && this.HP>0)
        {
            int fx=(int)(Math.random()*4);
            while((Maps.getMap(this.getLocation()).getDirection())[fx]==0)
            {
                fx=(int)(Math.random()*4);
            }
            YiDong(fx);
        }
    }
    public void taopao()//逃跑
    {
        int fx=(int)(Math.random()*4);
        while((Maps.getMap(this.getLocation()).getDirection())[fx]==0)
        {
            fx=(int)(Math.random()*4);
        }
        YiDong(fx);

    }
    //自动战斗
    public void autoZdou()
    {
        if(this.autozdou)
        {

        }
    }
    public void hufouhuofu()//复活恢复
    {
        this.siwang=false;
        this.HP = this.MaxHP;

        this.SP = this.MaxSP;

        this.MP = this.MaxMP;

        this.cultivationN = this.getMaxWg()*this.getMaxWg()*this.getMaxWg()/1000;
        this.cultivationY = 1;
        this.cultivationR = 1;

        this.setQxue();

    }
    public void huofu()//恢复
    {
        if((this.HP+(int)(this.MaxHP*(0.2)))>this.MaxHP)
        {
            this.HP = this.MaxHP;
        }else
        {
            this.HP = (this.HP+(int)(this.MaxHP*(0.2)));
        }
        if((this.SP+(int)(this.MaxSP*(0.2)))>this.MaxSP)
        {
            this.SP = this.MaxSP;
        }else
        {
            this.SP = (this.SP+(int)(this.MaxSP*(0.2)));
        }
        if((this.MP+(int)(this.MaxMP*(0.2)))>this.MaxMP)
        {
            this.MP = this.MaxMP;
        }else
        {
            this.MP = (this.MP+(int)(this.MaxMP*(0.2)));
        }
    }
    public void run()
    {
        while(true)
        {

            AutoXZ();
            huofu();
            try {
                Thread.sleep(2*60000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
